﻿if (!((window.DocumentTouch && document instanceof DocumentTouch) || 'ontouchstart' in window))
{
    var script = document.createElement("script");
    script.src = "Javascript/touch.js";
    var tag = $("head").append(script);
    $.os.android = true;
    $.os.desktop = true;
    if (getCookie("savepass") != null)
        document.getElementById("savepass").checked = true;
}
function Checklogin()
{
    if (queryString("unload") != null && queryString("unload") == "1")
    {
        window.history.forward(1);
        return;
    }
    else if(getCookie("savepass") != null && getCookie("savepass") != "")
    {
        window.location.href = "Default.aspx?SID=" + getCookie("savepass");
    } 
}
function login()
{
    var name = $('#username').val();
    var pass = $('#password').val();
    if (name == "" || pass == "")
    {
        alert("【账号】或【密码】不能为空!");
    }
    else
    {
        $.post('ProcTeacher/login.ashx', { uname: name, upass: pass }, function (data) { loginHome(data); });
    }
}
function loginHome(data) {
    if (data == "0") {
        alert("账号或密码错误！");
    }
    else {
        if (document.getElementById("css3").checked)
            SetCookie("savepass", data, 30);
        else
            deleteCookie("savepass"); alert(data);
        window.location.href = "Default.aspx?SID=" + data;
    }
}
function cancel()
{
    $('#username').val("");
    $('#password').val("");
}
function SetCookie(name,value,Days)//三个参数，一个是cookie的名子，一个是值,一个过期天数
{
    var exp = new Date();   
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}
function deleteCookie(name)
{
    if (getCookie(name) == null)
        return;
    SetCookie(name, "", 0);
}
var queryString = function (key)
{
    return (document.location.search.match(new RegExp("(?:^\\?|&)" + key + "=(.*?)(?=&|$)")) || ['', null])[1];
}   